package Euler57;

import java.math.*;
import ReusableCode.MathFunctions;

public class SquareRootConvergents {
	public static void main(String[] args) {
		BigInteger num = new BigInteger("3"); 
		BigInteger den = new BigInteger("2"); 
		int exp = 1, count = 0;
		
		while(exp <= 1000)
		{
			BigInteger oldNum = num, oldDen = den;
			
			num = oldNum.add(((new BigInteger("2")).multiply(oldDen)));
			den = oldNum.add(oldDen);
			
			//System.out.println(num + "/" + den);
			
			if(MathFunctions.numberOfDigits(num) > MathFunctions.numberOfDigits(den))
			{
				count++;
			}
			
			exp++;
		}
		
		System.out.println("Answer is: " + count);
	}
}